package me.zk.practice1.s;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
 * @author zhangkai
 * @date 2023/8/10 11:44
 */
public class LS20 {


    public boolean isValid(String s) {
        if (s.length() == 0) {
            return true;
        }

        Stack<Character> stack = new Stack<>();

        for (char c : s.toCharArray()) {
            if (c == '{') {
                stack.push('}');
            }
             else if (c=='[') {
                stack.push(']');
            }
            else if (c=='('){
                stack.push(')');
            } else {
                if (stack.empty() || c != stack.pop()) {
                    return false;
                }
            }

        }
        return stack.isEmpty();
    }
}
